package com.dmall.play.interview.chapter08;

import java.util.ArrayList;
import java.util.List;

public class Leetcode17V1 {

    private final static String[] LETTER_MAP = {
            " ",
            "",
            "abc",
            "def",
            "ghi",
            "jkl",
            "mno",
            "pqrs",
            "tuv",
            "wxyz"
    };

    private List<String> res = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        findCombinations(digits, 0, "");
        return res;
    }

    private void findCombinations(String digits, int index, String digit) {
        if (index == digits.length()) {
            res.add(digit);
            return;
        }
        char c = digits.charAt(index);
        String letter = LETTER_MAP[c - '0'];
        for (int i = 0; i < letter.length(); i++) {
            findCombinations(digits, index + 1, digit + letter.charAt(i));
        }
    }

    public static void main(String[] args) {
        Leetcode17V1 leetcode17 = new Leetcode17V1();
        List<String> strings = leetcode17.letterCombinations("23");
        System.out.println(strings);
    }
}
